package cn.zhz.privacy.sensitive.handler;

import cn.hutool.core.util.StrUtil;
import cn.zhz.privacy.sensitive.SensitiveType;
import cn.zhz.privacy.sensitive.SensitiveTypeHandler;

/**
 * 银行卡号脱敏
 * 只留前四位和后四位
 * 6227 0383 3938 3938 393 脱敏结果: 6227 **** **** ***8 393
 * @author chenhaiyang
 */
public class BandCardSensitiveHandler implements SensitiveTypeHandler{
    @Override
    public SensitiveType getSensitiveType() {
        return SensitiveType.BANK_CARD;
    }

    @Override
    public String handle(Object src) {
        if(src==null){
            return null;
        }
        String bankCard = src.toString();
        int len=bankCard.length();
        if(len<=8){
            return bankCard;
        }
        return StrUtil.subPre(bankCard, 4)
                .concat( "***********")
                .concat(StrUtil.subSufByLength(bankCard, 4));
    }
}
